import dayjs from "dayjs"
// 回显订单接单状态
export const orderStatusFilter = (val) => {
	const status  = Number(val)
	switch(status){
		case 1:
			return '待接单'
		case 2:
			return '待上门'
		case 3:
			return '维修中'
		case 4:
			return '待提交'
		case 5:
			return '待完成'
		case 6:
			return '已完成'
		case 7:
			return '异常单'
	}
}

/**
 * 接单时间节点
 * 1小时
 * @return {boolean} true 已超出15分钟，false 在15分钟内
 */
export const receiveNodeFilter = (val, max = 1 * 60 * 60 * 1000) => {
	if(typeof val !== "string") return false
	// 11:17
	// 10:17
	// 预约时间前1小时
	const endTime = dayjs(val).valueOf() - max
	// 当前时间戳
	const cureentTime = dayjs().valueOf()
	return cureentTime > endTime
}

// 按 今天、明天、日期显示时间
export const dayBriefFilter = (val) => {
	// 今天
	const currentDay = dayjs().format("YYYY-MM-DD")
	// 明天
	const nextDay = dayjs(currentDay).add(1, 'day').format("YYYY-MM-DD")
	const targetDay = dayjs(val).format("YYYY-MM-DD")
	if(targetDay === currentDay) return "今天"
	else if(targetDay === nextDay) return "明天"
	else return targetDay
}

// 截取时间内的 时-分
export const interceptTimeFilter = (val, format = "HH:mm") => {
	return dayjs(val).format(format)
}

export const mobilePrivacyFilter = (val) => {
	if(!val) return val
    var pho=/(\d{3})\d*(\d{4})/
    var str=val.replace(pho,'$1****$2');
	return str
}


export default {
	orderStatusFilter,
	receiveNodeFilter,
	dayBriefFilter,
	interceptTimeFilter,
	mobilePrivacyFilter
}